/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.Cipher;
import sun.misc.BASE64Encoder;

/**
 * Clase Jugador
 *
 * @author alumneDAM
 */
public class Jugador {

    private String nickname;
    private String nombre;
    private String pass;

    //Constructor de la clase Jugador
    public Jugador(String nick, String nombre, String password) {
        this.nickname = nick;
        this.nombre = nombre;
        this.pass = password;
    }

    /**
     * Método que encripta el password del jugador.
     *
     * @param Password
     */
    public String setPassword(String Password) {
        SecretKey clave;
        byte[] dato;
        String str = "";

        byte[] t = Password.getBytes();
        try {
            KeyGenerator kgen = kgen = KeyGenerator.getInstance("AES");
            kgen.init(128);
            clave = kgen.generateKey();
            Cipher c = Cipher.getInstance("AES/ECB/PKCS5Padding");
            c.init(Cipher.ENCRYPT_MODE, clave);
            dato = Password.getBytes("UTF-8");
            dato = c.doFinal(t);
            str = new BASE64Encoder().encode(dato);

        } catch (Exception e) {
        }
        return str;
    }

    public String getNickname() {
        return nickname;
    }

    public String getNombre() {
        return nombre;
    }

    public String getPass() {
        return pass;
    }

    @Override
    public String toString() {
        return "Jugador{" + "Nick=" + nickname + ", Nombre=" + nombre + ", Password=" + pass + '}';
    }
}
